package com.pingan.haofang.searchcloud.common.session;

import com.google.common.collect.Lists;
import com.pingan.haofang.searchcloud.common.filters.MockSessionFilter;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.session.web.http.DefaultCookieSerializer;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Component
@ConditionalOnBean(MockSessionFilter.class)
public class MockCookieSerializer extends DefaultCookieSerializer {

    public List<String> readCookieValues(HttpServletRequest request) {
        List<String> result = super.readCookieValues(request);
        if (CollectionUtils.isEmpty(result)) {
            return Lists.newArrayList("test-session");
        }
        return result;
    }

    public void writeCookieValue(CookieValue cookieValue) {

    }

}
